const os = require('os');

function getIpv4s(){
    const networkInterfaces = os.networkInterfaces();
    let allIPs = [];
    Object.keys(networkInterfaces).forEach((networkInterface) => {
      const addresses = networkInterfaces[networkInterface];
      addresses.forEach((address) => {
        // if (!address.internal && address.family === 'IPv4' && !address.address.startsWith('127.')) {
        // console.info(address)
        if (address.family === 'IPv4') {
          // 过滤掉内部 (如 127.0.0.1) 和 IPv6 地址
          allIPs.push(address.address);
        }
      });
    });
    return allIPs;
}

module.exports = getIpv4s;